using UnityEngine;
using System.Collections;

public class KonamiCode : MonoBehaviour 
{
	public KeyCode[] array;
    public int i = 0;

    public TextMesh[] macacoTexts;
    private bool completed = false;
    public float speed;

	void Update () 
	{
		if(Input.anyKeyDown)
		{
			CheckKey();
		}

        if(completed)
        {
            foreach(TextMesh macacoText in macacoTexts)
            {
                if(macacoText.transform.position.x > -70)
                {
                    macacoText.transform.position -= Vector3.right * speed * Time.deltaTime;
                }
                else
                {
                   completed = false;
                   macacoText.transform.position = new Vector3(15, macacoText.transform.position.y, macacoText.transform.position.z);
                }
            }
        }
	}
	
	void CheckKey()
	{
		if(i != array.Length)
		{
			if(Input.GetKeyDown(array[i]))
			{
				i++;

				if(i == array.Length)
				{
                    ChamaOMacaco();
				}
			}
			else
			{
				i = 0;
			}
		}
	}

    public void ChamaOMacaco()
    {
        if(!audio.isPlaying)
        {
            audio.Play();
        }

        completed = true;
        i = 0;     
    }
}